package com.pactera.asmp.server.controller.seaweedfs;

/**
 * @ProjectName: asmp-server
 * @Package com.pactera.asmp.server.controller.seaweedfs
 * @ClassName: SeaweedFsController
 * @Description: SeaweedFsController
 * @Date 2020/07/05 17:46
 * @Author lvzhiqiang
 * @Version 1.0
 */
//@RestController
//@RequestMapping("/file")
public class SeaweedFsController {

//    @Autowired
//    private SeaweedFsClient client;
//    @Value("${seaweedfs.host}")
//    private String host;
//    @Value("${seaweedfs.port}")
//    private int port;
//
//
//    @RequestMapping(value = "/upload", method = RequestMethod.POST)
//    public ResponseResult upload(@RequestParam("file") MultipartFile file) {
//        ResponseResult responseResult;
//        if(file == null){
//            responseResult = new ResponseResult(ResultCode.PARAM_IS_BLANK);
//            return responseResult;
//        }
//        SeaweedFsClient.SeaweedFsResponse response = new SeaweedFsClient.SeaweedFsResponse();
//        if (!file.isEmpty()) {
//            try {
//                response = client.saveFile(file);
//            } catch (IOException e) {
//                e.printStackTrace();
//                responseResult = new ResponseResult(ResultCode.SYSTEM_INNER_ERROR);
//                responseResult.setMessage(e.toString());
//                return responseResult;
//            }
//        }
//        responseResult = new ResponseResult(ResultCode.SUCCESS);
//        JSONObject jsonObject = (JSONObject) JSONObject.toJSON(response);
//        responseResult.setData(jsonObject);
//        return responseResult;
//    }
//
//
//    @RequestMapping(value = "/downloadUrl", method = RequestMethod.GET)
//    public String downloadUrl(@RequestParam("fileId") String fileId) {
//        String url = "";
//        try {
//            url = client.getFile(fileId);
//        } catch (IOException e) {
//            e.printStackTrace();
//        }
//        return url;
//    }
//
//    @RequestMapping(value = "/multi/upload", method = RequestMethod.POST)
//    public List<SeaweedFsClient.SeaweedFsResponse> handleFileUpload(HttpServletRequest request) {
//        List<MultipartFile> files = ((MultipartHttpServletRequest) request).getFiles("file");
//        List<SeaweedFsClient.SeaweedFsResponse> responses = new ArrayList<>();
//        if (files.size() != 0) {
//            for (MultipartFile temp : files) {
//                try {
//                    SeaweedFsClient.SeaweedFsResponse response = client.saveFile(temp);
//                    responses.add(response);
//                } catch (IOException e) {
//                    e.printStackTrace();
//                }
//            }
//        }
//        return responses;
//    }
}
